
<?php

class Application_Model_service_LogSystemService {
	
	protected static $_instance = null;
	
	protected function __construct() {
	
	}
	public static function getInstance() {
		if (self::$_instance == null) {
			self::$_instance = new self ();
		}
		return self::$_instance;
	}
	public function log($message) {
		require_once ('Zend/Log.php');
		require_once ('Zend/Log/Writer/Stream.php');
		$logger = new Zend_Log ();
		$uploadDir = realpath ( APPLICATION_PATH . '/log.txt' );
		$writer = new Zend_Log_Writer_Stream ( $uploadDir ); // open stream de ghi thong tin log vao
		$logger->addWriter ( $writer );
		
		$ip = new Zend_Controller_Request_Http ();
		$clientip = $ip->getClientIp ( false );
		$logger->log ( $clientip . "::" . $message, Zend_Log::INFO ); //ghi thong tin vao file
		$logger = null;
	}
	public function readLog() {
		$uploadDir = realpath ( APPLICATION_PATH . '/log.txt' );
			
			
		$lines = file ( $uploadDir );
				echo "<H2>THÔNG TIN ĐÃ ĐƯỢC LOG</H2>";
		foreach ( $lines as $line_num => $line ) {
			
			echo "$line_num $line";
			echo "<br>";
		}
	}

}